const gulp = require("gulp");
const babel = require("gulp-babel");
const watch = require("gulp-watch");
const rollup = require("gulp-rollup");
const replace = require("rollup-plugin-replace");

// 开发编译
gulp.task('dev', () => {
  return watch('./src/nodeuii/**/*.js',
    { ignoreInitial: false },
    () => {
      gulp.src('./src/nodeuii/**/*.js')
        .pipe(babel({
          //不让外部的.babelrc影响内部
          babelrc: false,
          "plugins": ["transform-es2015-modules-commonjs"]
        }))
        .pipe(gulp.dest('build'))
    }
  )
});

// 生产编译
gulp.task('prod', () => {
    gulp.src('./src/nodeuii/**/*.js')
      .pipe(babel({
        //不让外部的.babelrc影响内部
        babelrc: false,
        //ignore: ['./src/nodeuii/config/*.js'],
        "plugins": ["transform-es2015-modules-commonjs"]
      }))
      .pipe(gulp.dest('build'))
});
// 生产treeShaking
gulp.task('treeShaking', () => {
    gulp.src('./src/nodeuii/**/*.js')
      .pipe(rollup({
        //format CommonJS
        output:{format: "cjs"},          
        input: './src/nodeuii/config/index.js',
        plugins: [
          replace({
            "process.env.NODE_ENV": JSON.stringify('production')
          })
        ]
      }))
      .pipe(gulp.dest('build'))
});
